let express = require('express');
let expressJWT = require('express-jwt')
let cors = require('cors');


let app = express();
app.listen(3000, () => console.log("3000 端口已启用"))

app.use(cors());

app.use(express.urlencoded({
    extended: false
}));


app.use(expressJWT({
    secret: 'be-139',
    algorithms: ["HS256"]
}).unless({
    path: ["/user/login", "/user/reg"]
}))

// // // 登录
let login = require("./router/login.js")
app.use("/user", login);

let todo = require("./router/todo.js")
app.use("/todo", todo)




// 处理错误中间件
app.use(function (err, req, res, next) {
    if (err.name == "UnauthorizedError") {
        res.send({
            status: 1,
            message: "身份验证失败"
        });
    };
});